package wator.model.strategies;

import java.util.HashMap;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;

import wator.model.Agent;
import wator.model.IntegerVector;
import wator.model.MovementStrategy;
import wator.model.Neighborhood;
import wator.model.Simulation;

/**
 * This class is a null-object (GoF) implementation for the movement strategy.
 * Using this strategy assures that the individuals do not move at all.
 */
public class NoMovementStrategy implements MovementStrategy, Observer {

	private IntegerVector nullVector;
	
	/**
	 * Sole constructor. Initializes the null vector.
	 */
	public NoMovementStrategy() {
		super();
		nullVector = IntegerVector.getCubeVector(
				Simulation.getInstance().getSizeVector().getDimension(), 0);
		Simulation.getInstance().addObserver(this);
	}
	
	/**
	 * Returns the 0-vector unconditionally.
	 * 
	 * @param agent the agent (not used)
	 * @param neighborhood the agent's neighborhood (not used)
	 * @throws NullPointerException if agent is null.
	 */
	@Override
	public IntegerVector apply(Agent agent, Neighborhood neighborhood) {
		return nullVector;
	}

	/**
	 * This strategy has no parameters, this is a null object implementation.
	 * {@inheritDoc}
	 */
	@Override
	public void setParameter(String key, int value) {
		;
	}

	/**
	 * This strategy has no parameters, this is a null object implementation.
	 * {@inheritDoc}
	 */
	@Override
	public Map<String, Integer> getParameters() {
		return new HashMap<String, Integer>();
	}

	/* (non-Javadoc)
	 * @see wator.model.MovementStrategy#getName()
	 */
	@Override
	public String getName() {
		return "No Movement";
	}
	
	/**
	 * Reacts when the dimension of the size vector changes and updates
	 * the dimension of the null vector.
	 * {@inheritDoc}
	 */
	@Override
	public void update(Observable o, Object arg) {
		if (arg instanceof IntegerVector) {
			nullVector = IntegerVector.getCubeVector(
					((IntegerVector) arg).getDimension(), 0);
		}
	}
}
